interface Window {
	mdImageOnloadFn: Function;
	mdImageOnloadErrorFn: Function;
	onmdImageOnload: Function;
	onmdImageOnloadError: Function;
}

declare var window: Window & typeof globalThis;

// 文档区域图片事件列表
const mdImageEvent: {
	load: Function[];
	loadError: Function[];
} = {
	load: [],
	loadError: [],
};

/** 图片绑定的完成失败事件
 * @param {Event} event
 */
window.mdImageOnloadFn = function (event: Event) {
	mdImageEvent.load.forEach((item) => {
		item(event, Number((event.target as HTMLImageElement).dataset.id));
	});
};
/** 图片绑定的加载失败事件
 * @param {Event} event
 */
window.mdImageOnloadErrorFn = function (event: Event) {
	mdImageEvent.loadError.forEach((item) => {
		item(event, Number((event.target as HTMLImageElement).dataset.id));
	});
};

// 添加图片加载完成事件
window.onmdImageOnload = function (fn: Function) {
	mdImageEvent.load.push(fn);
};
// 添加图片加载失败事件
window.onmdImageOnloadError = function (fn: Function) {
	mdImageEvent.loadError.push(fn);
};
